<%@page import="java.util.List"%>
<%@ page contentType="text/html; charset=utf-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/functions" prefix="fn"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>维护字典</title>
</head>

<body>
	<style type="text/css"> 
#mytable {   
    padding: 0;
    margin: 0;   
    border-collapse:collapse;
}

td {
    border: 1px solid #C1DAD7;   
    background: #fff;
    font-size:11px;
    padding: 6px 6px 6px 12px;
    color: #4f6b72;
}

td.alt {
    background: #F5FAFA;
    color: #797268;
}

</style> 
<%
	List dictNameList = (List)request.getAttribute("dictNameList");
%>
<form id="form1" name="form1" action="" method="post">
<div>
	<fieldset style="width: 99%;">
					<legend>
						<span><b>字典基本信息</b></span>
					</legend>
					<table width="90%" cellspacing="1" align="center"  border="0" bordercolor="blue">
							<tr height="29">
								<td class="alt" align="right" class="tdBackGorund" width="5%">上级节点：</td>
								<td class="alt" style="text-align: left;  padding-left: 3px;padding-top: 5px;" width="15%" >
									<input id="parentName" name="parentName" type="text" value="${dictParentName}" readonly="readonly"/>
								    <input id="parentId" name="parentId" type="hidden" value="${parentId}"/>
									<input id="z1" name="z1" type="hidden" value="${dict.z1}"/>
									<input id="z4" name="z4" type="hidden" value="${dict.z4}"/>
									<input id="z41" name="z41" type="hidden" value="${dict.z41}"/>
									<input id="z11" name="z11" type="hidden" value="${dict.z11}"/>
								     <input type="hidden" id="dictId" name="dictId" value="${parentId}"/>
								</td>
							</tr>						
					
							<tr height="29">		
									<td class="alt" align="right" class="tdBackGorund" width="5%">字典名称：</td>
								<td style="text-align: left;  padding-left: 3px;padding-top: 5px;" width="15%">
								    <input id="z3" name="z3" type="text" value="${dict.z3}"  /><label style="color: red">★</label>
								    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
									顺序号：<input id="p12" name="p12" type="text" value="${dict.p12}" style="width:40px" />
																	
								</td>						
							
							</tr>
							<tr height="29">
								<td class="alt" align="right" class="tdBackGorund" width="5%">简码 ：</td>
								<td style="text-align: left;  padding-left: 3px;padding-top: 5px;"width="15%"> 
									<input id="p11" name="p11" type="text" value="${dict.p11}"/>
								</td>
							</tr>
							<!--  
							<tr height="29">
								<td class="alt" align="right" class="tdBackGorund" width="5%">关键字：</td>
								<td style="text-align: left;  padding-left: 3px;padding-top: 5px;"width="15%"> 
									<input id="z4" name="z4" type="text" value="${dict.z4}"/>
								</td>
							</tr>
							-->
							<tr height="29">
								<td class="alt" align="right" class="tdBackGorund" width="5%">字典说明：</td>
								<td style="text-align: left;  padding-left: 3px;padding-top: 5px;"width="15%"> 
									<input id="z5" name="z5" type="text" value="${dict.z5}"/>
								</td>	
							</tr>                           
							<tr height="29">
								<td class="alt" align="right" class="tdBackGorund" width="5%">显示方式：</td>
								<td style="text-align: left;  padding-left: 3px;padding-top: 5px;"width="15%"> 					
									<input type="radio" id="z9" value="0" name="z9" />顺序号
									<input type="radio" id="z9" value="1"  name="z9" />调用次数
									<script>
									jQuery("input[name='z9'][value=${dict.z9}]").attr("checked",true);</script>
								</td>
							</tr>
							 <tr height="29">								
								<td class="alt" align="right" class="tdBackGorund" width="5%">停用：</td>
								<td style="text-align: left;  padding-left: 3px;padding-top: 5px;">
									<select id="z13" name="z13" style="width: 155px">
										<option value="0">否</option>
										<option value="1">是</option>																		
									</select>
									<script>
									jQuery("#z13").val('${dict.z13}');
										</script>
								</td>							
							</tr>
							<tr >
								<td class="alt" align="right" class="tdBackGorund" width="5%">是否指标：</td>
								<td style="text-align: left;  padding-left: 3px;padding-top: 5px;"width="15%"> 									
									<input name="p22" type="radio" value="0"  ${dict.p22 ne '1'?'checked':''} />否
									<input name="p22"  type="radio"  value="1" ${dict.p22 eq '1'?'checked':''} />是
								</td>
							</tr>
							<tr id="reportType" style="display: none;">
								<td class="alt" align="right" class="tdBackGorund" width="5%">报送类型：</td>
								<td style="text-align: left;  padding-left: 3px;padding-top: 5px;"width="15%"> 									
									<input id="reportType1" name="p21"  type="checkbox" value="4"/>周报
									<input id="reportType2" name="p21"  type="checkbox" value="3"/>月报
									<input id="reportType3" name="p21"  type="checkbox" value="2"/>季报
									<input id="reportType4" name="p21"  type="checkbox" value="1"/>年报
								</td>
							</tr>	
							<tr height="29">
								<td class="alt" align="right" class="tdBackGorund" width="5%">属性1：</td>
								<td style="text-align: left;  padding-left: 3px;padding-top: 5px;"width="15%"> 
									<input id="z6" name="z6"  type="text" value="${dict.z6}"/>
									<input id="targetId" name="z6" type="hidden" value="${dict.z6}"  disabled="disabled"/>
									<input id="targetName" value="${fn:split(dict.z6,',')[1]}"  style="display: none" type="text"  onclick="showTargetForDict($('#targetName'),$('#targetId'),$('#targetName'))"/>									
								</td>		
							</tr>
								<tr height="29">
								<td class="alt" align="right" class="tdBackGorund" width="5%">属性2：</td>
								<td style="text-align: left;  padding-left: 3px;padding-top: 5px;"width="15%"> 
									<input id="z7" name="z7" type="text" value="${dict.z7}"/>
								</td>		
							</tr>
					
						<tr> 
						    <td colspan="2" align="center"><input type="button" value="保存" onclick="updateDict()"/><input type="button" value="返 回" onclick="returnMain()"/></td>
						</tr>
					</table>
				</fieldset>			
</div>
  
</table> 
</form>
<div id="selectTargetDiv"  style="display:none; position: absolute;z-index: 1003;background-color: white;width: 275px;height:220px;border:1px solid;overflow: auto;">
	<ul id="selectTree" class="ztree" style="margin-top:0; width:160px;"></ul>
</div> 
<script type="text/javascript">

function updateDict(){	
	var dictName = $('#z3').val();		
	<% 
		for(int i = 0; i < dictNameList.size(); i++){
			String dictName = dictNameList.get(i).toString();
			%>
			if(dictName == "<%=dictName%>" && dictName != '${dict.z3}'){
				alert("字典名称已存在，请重新填写");
				return null;
			}
			<%
		}
	%>
	var flag = validate();	
	if(flag){
		var formObj = document.getElementById("form1");
		formObj.action=ctx+'/ufmDict/updateDict';
		formObj.submit();
	}
}

function returnMain(){
	var formObj = document.getElementById("form1");
	formObj.action=ctx+'/ufmDict/findAll';
	formObj.submit();
	}

function validate(){
	var name = $("#z3").val();
	var ww = /^\s*$/;
	if(ww.test(name)){
  		alert("部门名称不能输入空格 ");
		return false;
  	}
	if(name==""){
		alert("请输入字典名称!");
		return false;
	}
	return true;
}
document.onclick = function(){
	var capzu = event.srcElement.id;
	if(capzu != 'targetName'){
		hideTableMenu();
	}  		
}
$(document).ready(function(){
	if('${dict.p22}'=='1'){
		$("#z6").hide();
		$("#targetName").show();
		$("#z6").attr("disabled",true);
		$("#targetId").attr("disabled",false);
		$("#reportType").show();	
	}
	if('${dict.p21}'!=''&&'${dict.p21}'!='null'){
		var reportTypes = '${dict.p21}'.split(",");
		if($.inArray("1", reportTypes)>=0){
			$("#reportType1").attr("checked", true);
		}
		if($.inArray("2", reportTypes)>=0){
			$("#reportType2").attr("checked", true);
		}
		if($.inArray("3", reportTypes)>=0){
			$("#reportType3").attr("checked", true);
		}
		if($.inArray("4", reportTypes)>=0){
			$("#reportType4").attr("checked", true);
		}
	}
	$('input[type="radio"][name="p22"]').click(function(){	
		if($(this).val()=="1"){
			$("#z6").hide();
			$("#targetName").show();
			$("#z6").attr("disabled",true);
			$("#targetId").attr("disabled",false);
			$("#reportType").show();
		}else{
			$("#z6").show();
			$("#targetName").hide();
			$("#targetId").attr("disabled",true);
			$("#z6").attr("disabled",false);
			$("#reportType").hide();
		}
	});
 });
function showTargetForDict(cityObj,hide,clickObj){
	if($("#selectTargetDiv").is(":hidden")){
		$("#selectTree").empty();
		getTargetTree(4);
		inputObj = cityObj;
		hideObj = hide;
		globalClickObj = clickObj;
		var cityOffset = cityObj.offset();
		$("#selectTargetDiv").css({
			left : cityOffset.left + "px",
			top : cityOffset.top + cityObj.outerHeight() + "px"
		}).slideDown("fast");
	}else{
		$("#selectTargetDiv").fadeOut("fast");
	}
}
function hideTableMenu(){
	   $("#selectTargetDiv").fadeOut("fast");
}
function getTargetTree(type){
	var url = "/FPM/Target/getTreeForNew?treeType="+type;
	var setting1 = {
			async : {
				enable : true,
				url :url 
			},		
			view : {
				dblClickExpand : false
			},
			data : {
				simpleData : {
					enable : true
				}
			},
			callback : {
				onClick : onClickForTable,
				onAsyncSuccess: openAll
			},
			
		};
	$.fn.zTree.init($("#selectTree"), setting1);
}
function onClickForTable(e, treeId, treeNode){
	   if(treeNode.isParent){
		   alert("只能选择指标!");
	   }else{
		    $("#targetName").attr("value", treeNode.name);
			$("#targetId").attr("value",treeNode.id.replace("tb","").replace("tr","").replace("nt","")+","+treeNode.name);
			hideTableMenu();
	   }
}
function openAll(){
	var treeObj = $.fn.zTree.getZTreeObj("selectTree");
	treeObj.expandAll(true);
}  
</script>
</body>
</html>
